﻿using System;
using SFML.Window;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Transformable_Engine_v2.Engine.Input
{
    public static class MouseHandler
    {
        public delegate void OnClickHandler(TE_Vector2 position);

        public static event OnClickHandler OnMouseClick;
        public static event OnClickHandler OnMouseRelease;

        private static TE_Vector2 _mousePosition = TE_Vector2.MinValue;
        public static TE_Vector2 MousePosition
        {
            get { return _mousePosition; }
            set { _mousePosition = value; }
        }

        public static void Update(TimeSpan gameTime, SFML.Window.Window window)
        {
            var position = Mouse.GetPosition(window);
            MousePosition = new TE_Vector2(position.X, position.Y);
        }

        public static void OnClick(object sender,
                                   MouseButtonEventArgs eventArgs)
        {
            if(OnMouseClick != null)
                OnMouseClick(new TE_Vector2(eventArgs.X, eventArgs.Y));
        }

        public static void OnRelease(object sender,
                                     MouseButtonEventArgs eventArgs)
        {
            if(OnMouseRelease != null)
                OnMouseRelease(new TE_Vector2(eventArgs.X, eventArgs.Y));
        }
    }
}